<?php
header ('Content-type: text/html; charset=utf-8');
define('DS', DIRECTORY_SEPARATOR);
defined('APP_PATH') ? null : define('APP_PATH', '..' . DS . 'application');

require_once (APP_PATH . DS . 'initialize.php');

if (@$_SESSION['logged_in'])
{
	redirect_to("../../index.php");
}
?>
<?php
// Remember to give your form's submit tag a name="submit" attribute!
if (isset($_POST['submit'])) { // Form has been submitted.

	$username = trim($_POST['username']);
	$password = trim($_POST['password']);

	// Check database to see if username/password exist.
	$userObj = new User();
	$found_user = $userObj->authenticate($username, $password);

	if ($found_user) {

		$session->login($found_user);
		//log_action('Login', "{$found_user->username} logged in.");
		//$message = "Log in success";
		redirect_to("../../index.php");
	} else {
		if($_SESSION['empty_user']){
			$session->message("User does not exist, plaease create new user first!.");
			redirect_to("create_user.php");
		}else{
			// username/password combo was not found in the database
			$message = "Username or password is incorrect.";
		}
		
	}

} else { // Form has not been submitted.
	$username = "";
	$password = "";
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="author" content="snopeborn" />

<title>Login</title>
</head>

<body>

<?php

//include_layout_template('admin_header.php');

?>

<!--h2>Login</h2-->
<?php 
//Print message
echo output_message($message); 
//Clear message
$session->message(""); 
?>
<div align="center" style='border:1px solid #4a007d; width:400px; margin-left:auto;margin-right:auto; margin-top:60px;padding:40px; padding-bottom:2px;'>
<img src='image/mcot.jpg' align='center' /><p>MCOT&nbsp;&nbsp;LIVE&nbsp;&nbsp;FEED&nbsp;&nbsp;MANAGER</p><hr/>
<form action="login.php" method="post">
<table>
	<tr>
		<td>Username : </td>
		<td><input type="text" name="username" maxlength="30"
			value="<?php echo htmlentities($username); ?>" /></td>
	</tr>
	<tr>
		<td>Password : </td>
		<td><input type="password" name="password" maxlength="30"
			value="<?php echo htmlentities($password); ?>" /></td>
	</tr>
	<tr>
		<td colspan="2"><input type="submit" name="submit" value="Login" style='padding:15px 40px; float:right; margin-top:6px'/></td>
	</tr>
</table>
</form>

<div style='text-align:right; margin-top:20px; font-size:.8em;'><span><a href='change_password.php'>Change password</a></span>
&nbsp;&nbsp;
<!--span> <a href='../index.html'>Help</a> </span--></div>
</div>
<?php

//include_layout_template('admin_footer.php');

?>
</body>
</html>
